
//
//  HomeBottomView.m
//  WisdomCommunity
//
//  Created by Yahaong on 16/7/22.
//  Copyright © 2016年 zonten. All rights reserved.
//

#import "CommunityBottomView.h"
#import "YHMarcros.h"

@interface CommunityBottomView ()
@property (nonatomic, strong)UIButton *m_btnDoctor;
@property (nonatomic, strong)UIButton *m_btnIllegaldriv;
@property (nonatomic, strong)UIButton *m_btnDelivery;
@property (nonatomic, strong)UIButton *m_btnShopping;
@property (nonatomic, strong)UIButton *m_btnIdlemarket;

@end
@implementation CommunityBottomView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
        self.userInteractionEnabled = NO;
    }
    return self;
}

- (void)setupUI
{
    self.autoresizingMask = UIViewAutoresizingNone;
    self.backgroundColor = kBgColor;
    [self addSubview:self.m_btnDoctor];
    [self.m_btnDoctor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.5);
        make.height.equalTo(self).multipliedBy(0.5);
    }];
    [self addSubview:self.m_btnIllegaldriv];
    [self.m_btnIllegaldriv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.leading.equalTo(self.m_btnDoctor.trailing).offset(1);
        make.trailing.equalTo(self);
        make.bottom.equalTo(self.m_btnDoctor.bottom);
    }];
    
    [self addSubview:self.m_btnDelivery];
    [self.m_btnDelivery mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_btnDoctor.bottom).offset(1);
        make.leading.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.333);
        make.bottom.equalTo(self);
    }];
    [self addSubview:self.m_btnShopping];
    [self.m_btnShopping mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_btnDelivery);
        make.leading.equalTo(self.m_btnDelivery.trailing).offset(1);
        make.width.equalTo(self.m_btnDelivery);
        make.bottom.equalTo(self.m_btnDelivery);
    }];
    
    [self addSubview:self.m_btnIdlemarket];
    [self.m_btnIdlemarket mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m_btnDelivery);
        make.trailing.equalTo(self);
        make.leading.equalTo(self.m_btnShopping.trailing).offset(1);
        make.bottom.equalTo(self.m_btnDelivery);
    }];
    
}
- (void)buttonClick:(UIButton *)button
{
    if (!self.delegate || ![self.delegate respondsToSelector:@selector(communityBottomViewDidClick:)])
    {
        return;
    }
    [self.delegate communityBottomViewDidClick:button.tag];
    
}
#pragma mark - lazy loading 

- (UIButton *)m_btnDoctor
{
    if (!_m_btnDoctor) {
        _m_btnDoctor  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnDoctor setImage:[UIImage imageNamed:@"community_icon_doctor"] forState:UIControlStateNormal];
        [_m_btnDoctor setImage:[UIImage imageNamed:@"community_icon_doctor"] forState:UIControlStateHighlighted];
        [_m_btnDoctor addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        _m_btnDoctor.tag = 0;
        _m_btnDoctor.backgroundColor = [UIColor whiteColor];
    }
    return _m_btnDoctor;
}

- (UIButton *)m_btnIllegaldriv
{
    if (!_m_btnIllegaldriv) {
        _m_btnIllegaldriv  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnIllegaldriv setImage:[UIImage imageNamed:@"community_icon_Illegaldriving"] forState:UIControlStateNormal];
        [_m_btnIllegaldriv setImage:[UIImage imageNamed:@"community_icon_Illegaldriving"] forState:UIControlStateHighlighted];
        [_m_btnIllegaldriv addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        _m_btnIllegaldriv.tag = 1;
        _m_btnIllegaldriv.backgroundColor = [UIColor whiteColor];
    }
    return _m_btnIllegaldriv;
}
- (UIButton *)m_btnDelivery
{
    if (!_m_btnDelivery) {
        _m_btnDelivery  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnDelivery setImage:[UIImage imageNamed:@"community_icon_delivery"] forState:UIControlStateNormal];
        [_m_btnDelivery setImage:[UIImage imageNamed:@"community_icon_delivery"] forState:UIControlStateHighlighted];
        [_m_btnDelivery addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
         _m_btnDelivery.tag = 2;
        _m_btnDelivery.backgroundColor = [UIColor whiteColor];
    }
    return _m_btnDelivery;
}


- (UIButton *)m_btnShopping
{
    if (!_m_btnShopping) {
        _m_btnShopping  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnShopping setImage:[UIImage imageNamed:@"community_icon_shopping"] forState:UIControlStateNormal];
        [_m_btnShopping setImage:[UIImage imageNamed:@"community_icon_shopping"] forState:UIControlStateHighlighted];
        [_m_btnShopping addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        _m_btnShopping.tag = 3;
        _m_btnShopping.backgroundColor = [UIColor whiteColor];
    }
    return _m_btnShopping;
}


- (UIButton *)m_btnIdlemarket
{
    if (!_m_btnIdlemarket) {
        _m_btnIdlemarket  = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m_btnIdlemarket setImage:[UIImage imageNamed:@"community_icon_Idlemarket"] forState:UIControlStateNormal];
        [_m_btnIdlemarket setImage:[UIImage imageNamed:@"community_icon_Idlemarket"] forState:UIControlStateHighlighted];
        [_m_btnIdlemarket addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
         _m_btnIdlemarket.tag = 4;
        _m_btnIdlemarket.backgroundColor = [UIColor whiteColor];
    }
    return _m_btnIdlemarket;
}

@end
